package com.lmax.disruptor.custom.demo;

import com.lmax.disruptor.EventHandler;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class TradeHandler implements EventHandler<Trade>
{

    private String name;

    public TradeHandler(final String name)
    {
        this.name = name;
    }

    public void onEvent(final Trade event) throws Exception
    {
        //生成订单id
        event.setId(UUID.randomUUID().toString());
        TimeUnit.SECONDS.sleep(1);
//        System.out.println(name + "---" + event);
    }

    @Override
    public void onEvent(final Trade event, final long sequence, final boolean endOfBatch) throws Exception
    {
        System.out.println("----" + name + "  handle process " + sequence);
        this.onEvent(event);
    }
}
